home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #11 / Amiga Plus CD - 2002 - No. 11.iso / Tools / ShareMailGiftware / MultiRen / Developers / Test-Plugin.mrp.c < prev    next >
C/C++ Source or Header  |  2002-10-27  |  5KB  |  163 lines

  1. /* Test-plugin v1.1a rev.#2 by Deniil 715! for MultiRen
  2.    Made 2002-05-24
  3.  
  4.    E-mail to me, Daniel Westerberg: deniil@algonet.se
  5. */
  6.  
  7. #include<proto/exec.h>
  8. #include<proto/dos.h>
  9. #include<proto/intuition.h>
  10. #include<exec/tasks.h>
  11. #include<intuition/intuition.h>
  12. #include<stdlib.h>
  13. #include<stdio.h>
  14.  
  15. #define _VER "$VER: Test-plugin v1.1a by Deniil 715! rev.#2 (2002-05-24)"
  16. #define NUMSTRINGS_FOR_THIS_PLUGIN 2
  17. #define FILE_NAME_LENGTH 512
  18. #define COM_ASK 1
  19. #define COM_EXTRACT 2
  20. #define COM_CONFIGURE 3
  21. #define COM_ABOUT 4
  22. #define COM_QUIT 5
  23. #define ERR_OK 0
  24. #define ERR_NOMEM 1
  25. #define ERR_NOFILE 2
  26. #define ERR_NOSIG 3
  27. #define ERR_NOTIMPL 4
  28. #define ERR_UNKNOWN 5
  29. #define ERR_OTHER 6
  30. #define ERR_WRONGFORMAT 7
  31. #define ERR_NOINFO 8
  32. #define ERR_FATAL 20
  33.  
  34. struct multiren_plugin {
  35.   long id;
  36.   struct Task *task;
  37.   long sig;
  38.   short ret;
  39.   char command;
  40.   char numstrings;       /* You will */
  41.   char *stringlist[256]; /* only use */
  42.   char *name;            /* these 4 */
  43.   char newname;          /* elements */
  44. };
  45.  
  46. short ask(void);
  47. short extract(void);
  48. short configure(void);
  49. short about(void);
  50. short cleanup(void);
  51. short req(char*,char*);
  52.  
  53. /* I needed this line to make it work with vbcc:
  54. struct IntuitionBase *IntuitionBase;
  55. */
  56. struct multiren_plugin *mrp;
  57. char ascii[5], hex[9];
  58.  
  59. int main(int argc,char *argv[]) {
  60.   char sigbit;
  61.   long sig, msig;
  62.   struct Task *mtask;
  63.   if(DOSBase=(struct DosLibrary*)OpenLibrary("dos.library",0)) {
  64.     if(IntuitionBase=(struct IntuitionBase*)OpenLibrary("intuition.library",0)) {
  65.       if(argc==2) {
  66.         if(mrp=(struct multiren_plugin*)atol(argv[1])) {
  67.           if(mrp->id==*(long*)"MRPO") {
  68.             if((sigbit=AllocSignal(-1))>=0) {
  69.               sig=1<<sigbit;
  70.               while(1) {
  71.                 switch(mrp->command) {
  72.                 case COM_ASK:
  73.                   mtask=mrp->task;
  74.                   msig=mrp->sig;
  75.                   mrp->ret=ask();
  76.                   SetProgramName(mrp->name);
  77.                   mrp->task=FindTask(0L);
  78.                   mrp->sig=sig;
  79.                   break;
  80.                 case COM_EXTRACT:   mrp->ret=extract(); break;
  81.                 case COM_CONFIGURE: mrp->ret=configure(); break;
  82.                 case COM_ABOUT:     mrp->ret=about(); break;
  83.                 case COM_QUIT:
  84.                   mrp->ret=cleanup();
  85.                   FreeSignal(sigbit);
  86.                   CloseLibrary((struct Library*)DOSBase);
  87.                   Signal(mtask,msig);
  88.                   return 0;
  89.                 default:
  90.                   mrp->ret=ERR_UNKNOWN;
  91.                 }
  92.                 Signal(mtask,msig);
  93.                 Wait(sig);
  94.               }
  95.             }
  96.             else {
  97.               mrp->ret=ERR_NOSIG;
  98.               Signal(mrp->task,mrp->sig);
  99.               return 0;
  100.             }
  101.           }
  102.         }
  103.       }
  104.       CloseLibrary((struct Library*)IntuitionBase);
  105.     }
  106.     CloseLibrary((struct Library*)DOSBase);
  107.   }
  108.   printf("This is a plugin for MultiRen!\n"
  109.          "It is not supposed to be executed manually!\n"
  110.          "Use it through the Renplacer tool in MultiRen instead!\n");
  111.   return ERR_FATAL;
  112. }
  113.  
  114. short ask() {
  115.   mrp->numstrings=NUMSTRINGS_FOR_THIS_PLUGIN;  /* I will return 2 strings */
  116.   mrp->stringlist[0]="First 4 bytes as hex";   /* Setting information-strings */
  117.   mrp->stringlist[1]="First 4 bytes as ASCII";
  118.   mrp->name="Test Plugin"; /* This plugins name */
  119.   mrp->newname=0;          /* This plugin reads info from the file and it is
  120.                               therefor unwise to request newname as it changes
  121.                               and the file will not be found. */
  122.   return ERR_OK; /* This plugin can't fail in initiation */
  123. }
  124.  
  125. short extract() { /* Do my stuff.. */
  126.   BPTR fh;
  127.   long len;
  128.   if(fh=Open(mrp->name,MODE_OLDFILE)) { /* Open the file that later is going to be renamed. */
  129.     len=Read(fh,ascii,4L);
  130.     Close(fh);
  131.     hex[8]='\0';
  132.     ascii[4]='\0';
  133.     if(len!=4L) return ERR_OTHER;
  134.     sprintf(hex,"%08lX",*(long*)ascii);
  135.     mrp->stringlist[0]=hex;   /* Set the pointer so that MultiRen.. */
  136.     mrp->stringlist[1]=ascii; /* ..can get my strings. */
  137.     return ERR_OK; /* My stuff went ok */
  138.   }
  139.   return ERR_NOFILE; /* The file didn't open */
  140. }
  141.  
  142. short configure() { return ERR_NOTIMPL; } /* There is no config for this plugin */
  143.  
  144. short about() {
  145.   if(req("Test Plugin v1.1a rev.#2 by Deniil 715! for MultiRen\n\n"
  146.          "It was made 2002-05-24 in Amiga-E\n\n"
  147.          "E-mail: deniil@algonet.se","More|OK"))
  148.     req("This plugin will return the first 4 bytes\n"
  149.         "of the file to rename in two ways. The first\n"
  150.         "string will be the 4 bytes in hexadecimal,\n"
  151.         "the other one just as a plain string.","OK");
  152.   return ERR_OK;
  153. }
  154.  
  155. short cleanup() { return ERR_OK; }
  156.  
  157. short req(char *body,char *gads) {
  158.   struct EasyStruct tags;
  159.   tags.es_Title="Test Plugin";
  160.   tags.es_TextFormat=body;
  161.   tags.es_GadgetFormat=gads;
  162.   return EasyRequestArgs(NULL,&tags,NULL,NULL);
  163. }